package com.team7.happycommunity.businessservice.mq;

import com.rabbitmq.client.Channel;
import com.team7.happycommunity.businessservice.service.ServiceOrderService;
import com.team7.happycommunity.businessservice.util.SendSms;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

@Service
public class RefundCode {

    @Resource
    private ServiceOrderService serviceOrderService;


    @RabbitHandler
    @RabbitListener(queues = "refund_code_queue")
    public void processPay(@Payload Map msg, Channel channel, @Headers Map headers){
        Integer id = (Integer) msg.get("id");
        Integer status = (Integer)msg.get("status");
        //修改状态
        serviceOrderService.updateById(id,status);
        //签收
        Long tag=(Long)headers.get(AmqpHeaders.DELIVERY_TAG);
        try {
            channel.basicAck(tag,false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
